import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class SurveyResult extends HttpServlet {
    private static final long serialVersionUID = 2536653679495398250L;

    @Override
    public void init(ServletConfig config) {
        System.out.println("初始化servlet实例");
    }

    @Override
    public void destroy() {
        System.out.println("销毁servlet实例");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("<html>");
        out.print("<head>");
        out.print("<meta charset=UTF-8>");
        out.print("<title>调查结果</title>");
        out.print("</head>");
        out.print("<body>");
        out.print("你主要使用的编程语言：<br>");
        String[] items = req.getParameterValues("item");
        for (String item : items) {
            out.print(item + "<br>");
        }
        out.print("</body>");
        out.print("</html>");
    }
}
